<?php
//require './common.inc.php';

//require 'global.func.php';
require 'ads.class.php';
$c_ads = new ads();



switch($action){
	case 'view':
		if(!$adsid) return false;
		$ads = $c_ads->get_info($adsid);
		if($ads['disabled'] == 1) return false;
		//dump($ads);
		
		switch($ads['type']){
		
			case 'image':
				$c = $ads['linkurl'] ? "<a href='index.php?module=ads&action=click&adsid=$adsid' target='_blank'><img src='".SITE_URL."$ads[imageurl]' alt='$ads[alt]' border='0'/></a>" : "<img src='".SITE_URL."$ads[imageurl]' alt='$ads[alt]' border='0'/>";
			break;
			
			case 'flash':
				$c = "<embed name='Movie1' src='".SITE_URL.$ads['flashurl']."' quality='high' width='100%' height='100%' wmode='transparent' type='application/x-shockwave-flash'> </embed> ";
			break;
			
			case 'text':
				$c = "$ads[text]";
			break;
			
			case 'code':
				$c = "<a href='$ads[linkurl]' title='$ads[code]' target='_blank'>$ads[code]</a>";
			break;
		} 
		echo "document.write(\"$c\");";
	break;
	
	case 'click':
		$adsid = intval($adsid);
		$ads = $c_ads->get_info($adsid);
		
		if($ads)
		{
			$db->query("UPDATE ".DB_PRE."ads SET `clicks`=clicks+1 WHERE adsid=".$ads['adsid']);
			$info['username'] = $_username;
			$info['clicktime'] = time();
			$info['ip'] = IP;
			$info['adsid'] = $id;
			$info['referer'] = HTTP_REFERER;
			$table = DB_PRE.'ads_stat';
			$db->insert($table, $info);
			$url = strpos($ads['linkurl'], 'http://')===FALSE ? 'http://'.$ads['linkurl'] : $ads['linkurl'];
		}
		header("Location: $url");
	break;
	
	default:
		if(isset($page)) $page = max(intval($page), 1);
		$pagesize = $M['pagesize'] ? intval($M['pagesize']) : 12;
		$count = $db->get_one("SELECT COUNT(*)  AS num FROM ".DB_PRE."ads_place WHERE disabled=1");
		$mumber = $count['num'];
		$pages = pages($mumber, $page, $pagesize);
		$offset = ($page-1)*$pagesize;
		$places = $adses = array();
		$places= $place->manage('WHERE disabled=1', 1);
		include template($module.'_index');
	break;
}

?> 